package com.face.mapper;

import com.face.entity.Role;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RoleMapper {

    @Select("select * from tb_role where shopId = #{shopId}")
    List<Role> findPage(String shopId);

    @Insert("insert into tb_role (name, description, permissions, status, shopId, createtime, updatetime, enable_notify) values(#{name}, #{description}, #{permissions}, #{status}, #{shopId}, #{createtime}, #{updatetime}, #{enableNotify})")
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Integer.class)
    Integer save(Role role);

    @Select("select * from tb_role where id = #{id}")
    Role findById(Integer id);

    @Update("update tb_role set name = #{name}, description = #{description}, permissions = #{permissions}, enable_notify = #{enableNotify} where id = #{id}")
    void update(Role role);

    @Update("update tb_role set status = #{status} where id = #{id}")
    void updateStatus(Integer id, Integer status);

    @Select("select * from tb_role where shopId = #{shopId} and name like CONCAT('%',#{name},'%') and status = #{status}")
    List<Role> findPageByNameAndStatus(String shopId, String name, Integer status);

    @Select("select * from tb_role where shopId = #{shopId} and name like CONCAT('%',#{name},'%') ")
    List<Role> findPageByName(String shopId, String name);

    @Select("select * from tb_role where shopId = #{shopId} and status = #{status}")
    List<Role> findPageByStatus(String shopId, Integer status);

    @Select("select * from tb_role where shopId = #{shopId} and name = #{name}")
    Role findByName(String name, String shopId);

    @Select("select a.* from tb_role a left join tb_account b on a.id = b.roleId  where b.openid = #{openid}")
    Role findByOpenid(String openid);

}
